home *** CD-ROM | disk | FTP | other *** search
- Path: news.bridge.net!news
- From: David Byrden <100101.2547@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: What is referencing good for?
- Date: 25 Feb 1996 22:04:19 GMT
- Organization: self-employed
- Message-ID: <4gqmd3$ci3@news.bridge.net>
- References: <4goojd$a9g@wintermute.ecs.fullerton.edu> <4goutn$31u@news.bridge.net> <3130c026.8571250@news2.cts.com>
- NNTP-Posting-Host: ppp-mia1-43.bridge.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
-
- >>>>>
- int& operator[] ( int index )
- > {
- > return dataBlock [ index ] ;
- > }
- > // constructor etc etc
- >} ;
- >
- >
- >
- > array ar ;
- > ar[4] = 0 ; // can't be done with pointers
- >
- >
- <<<<<
-
-
- >Good example, but.... the next question begs to be answered. Why
- >would anybody want to do this? It essentially gives public access to
- >datablock, which is a private variable.
-
-
- Oh no, it does not. There is no way to modify dataBlock. You can find
- out what value is in it by taking the address
-
- & ar[0]
-
- but that does not even prove that dataBlock exists - I could eliminate
- dataBlock, store that address in a completely different format, and then
- rewrite the operator function to work in exactly the same way as seen
- from outside.
-
- David
-
-
-